﻿using SimStatus.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SimStatus.UI
{
    /// <summary>
    /// Install_Creating.xaml 的交互逻辑
    /// </summary>
    public partial class Install_Creating : UserControl, IContent
    {
        public Install_Creating()
        {
            InitializeComponent();
            this.Loaded += Install_Creating_Loaded;
        }

        public IMainPage main { get; set; }

        void Install_Creating_Loaded(object sender, RoutedEventArgs e)
        {
            this.blk_CreateConnection.Visibility = Visibility.Collapsed;
            this.blk_Reg.Visibility = Visibility.Collapsed;
            this.blk_TestConnection.Visibility = Visibility.Collapsed;
            this.Next.Visibility = Visibility.Collapsed;
            this.txt_content.Text = main.DialerName;
        }

        public void Do()
        {
            //创建移动数据连接
            
            var createStatus = main.CreateDial();
            if (createStatus)
            {
                this.blk_CreateConnection.Visibility = Visibility.Visible;
                Jpp.DoEvent();
            }
            else
            {
                main.ShowContent(new Errors.Status() { Msg = "创建连接时发生了一个错误", Content = "这可能是由于权限不足引起的。请使用管理员权限重新运行本程序。" });
                Jpp.DoEvent();
                return;
            }

            //测试移动数据连接
            
            var dialstatus = main.Dial();
            main.Logs.Add(new Log() { LogName="dialstatus", LogContent=dialstatus, LogType="info" });
            this.blk_TestConnection.Visibility = Visibility.Visible;
            Jpp.DoEvent();

            //注册
           var regstatus = main.ExcuteCMD(Environment.CurrentDirectory + "\\SimStatus.Console.exe Reg");
           main.Logs.Add(new Log() { LogName = "regstatus", LogContent = regstatus, LogType = "info" });
           this.blk_Reg.Visibility = Visibility.Visible;
           Jpp.DoEvent();

           this.Next.Visibility = Visibility.Visible;
           Jpp.DoEvent();
        }

        private void Next_Click(object sender, RoutedEventArgs e)
        {
            MainBoard content = new MainBoard();
            content.main = this.main;
            main.ShowContent(content);
            Jpp.DoEvent();
            
        }
    }
}
